<template>
	<view class="">
		<image :src="url" mode="" @click="sfzz"></image>
	</view>
</template>

<script>
	export default {
		props: {

		},
		data() {
			return {
				upUrl: "http://youjialibo.wm76.mtnet.ren/api/upload/upload_field",
				url: "http://youjialibo.wm76.mtnet.ren/upload/20210902/737c862f6f17ef1893e7bd06bd6e0adf.png"
			}
		},
		methods: {
			sfzz() {
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(chooseImageRes) {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.showLoading({
							title: '上传中'
						});
						uni.uploadFile({
							count: 1,
							url: that.upUrl, //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: "file",
							// size:"1000",
							formData: {
								user: "test",
							},
							success: (uploadFileRes) => {
								uni.hideLoading();
								if (!JSON.parse(uploadFileRes.data).data.url) {
									return
								}
								that.url = "http://youjialibo.wm76.mtnet.ren" + JSON.parse(uploadFileRes.data).data.url
								that.$emit('successImg', JSON.parse(uploadFileRes.data).data.url)
							},
						});
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	image {
		// width: 213rpx;
		width: 300rpx;
		height: 210rpx;
		display: block;
		// margin-top: 30rpx;
		margin: 0 auto;
	}
</style>
